package com.example.administrator.easy.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.easy.R;
import com.example.administrator.easy.model.GuangRqStarItems;
import com.example.administrator.easy.model.GuangRqStarResult;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/11/14.
 */

public class GuangRqStarLvAdapter extends BaseAdapter {//
    private Context mContext;
    private List<GuangRqStarItems> mList;
    private List<GuangRqStarResult> mFList;
    private ImageOptions options;

    public GuangRqStarLvAdapter(Context context,List<GuangRqStarItems> list,List<GuangRqStarResult> fList){
        mContext = context;
        mList = list;
        mFList = fList;
        options = new ImageOptions.Builder().setUseMemCache(true).build();

    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        if(position==0){
            return mFList.get(0);
        }
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        if(position==0){
            return 0;
        }
        return 1;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (position==0) {
            ViewHolder1 vh1;
            if(convertView==null){
                convertView = View.inflate(mContext,R.layout.fragment_gaung_rqstar_item_one,null);
                vh1 = new ViewHolder1(convertView);
                convertView.setTag(vh1);
            }else {
                vh1 = (ViewHolder1) convertView.getTag();
            }
            vh1.tvname1.setText(mFList.get(0).getItems().get(1).getStarName());
            vh1.tvname2.setText(mFList.get(0).getItems().get(0).getStarName());
            vh1.tvname3.setText(mFList.get(0).getItems().get(2).getStarName());
            vh1.tv1.setText("活跃度 "+mFList.get(0).getItems().get(1).getLate7DayPoints());
            vh1.tv2.setText("活跃度 "+mFList.get(0).getItems().get(0).getLate7DayPoints());
            vh1.tv3.setText("活跃度 "+mFList.get(0).getItems().get(2).getLate7DayPoints());
            //图片
            x.image().bind(vh1.iv1,mFList.get(0).getItems().get(1).getAvatar(),options);
            x.image().bind(vh1.iv2,mFList.get(0).getItems().get(0).getAvatar(),options);
            x.image().bind(vh1.iv3,mFList.get(0).getItems().get(2).getAvatar(),options);

        }else{
            ViewHolder2 vh2;
            if(convertView==null){
                convertView = View.inflate(mContext,R.layout.fragment_guang_rqstar_item_two,null);
                vh2 = new ViewHolder2(convertView);
                convertView.setTag(vh2);
            }else{
                vh2 = (ViewHolder2) convertView.getTag();
            }
            vh2.tvpai.setText(mList.get(position-1).getId());
            vh2.tvname.setText(mList.get(position-1).getStarName());
            vh2.tvhuo.setText("活跃度"+mList.get(position-1).getLate7DayPoints());
            x.image().bind(vh2.iv,mList.get(position-1).getAvatar(),options);
        }
        return convertView;
    }
    class ViewHolder1{
        TextView tvname1,tvname2,tvname3,tv1,tv2,tv3;
        ImageView iv1,iv2,iv3;
        public ViewHolder1(View view){
            tvname1 = (TextView) view.findViewById(R.id.tvname1);
            tvname2 = (TextView) view.findViewById(R.id.tvname2);
            tvname3 = (TextView) view.findViewById(R.id.tvname3);
            tv1 = (TextView) view.findViewById(R.id.tvhuoyuedu1);
            tv2 = (TextView) view.findViewById(R.id.tvhuoyuedu2);
            tv3 = (TextView) view.findViewById(R.id.tvhuoyuedu3);
            iv1 = (ImageView) view.findViewById(R.id.iv1);
            iv2 = (ImageView) view.findViewById(R.id.iv2);
            iv3 = (ImageView) view.findViewById(R.id.iv3);
        }
    }
    class ViewHolder2{
        TextView tvpai,tvname,tvhuo;
        ImageView iv;
        public ViewHolder2(View view){
            tvpai = (TextView) view.findViewById(R.id.tvpaiming);
            tvname = (TextView) view.findViewById(R.id.tvname);
            tvhuo = (TextView) view.findViewById(R.id.tvhuoyuedu);
            iv = (ImageView) view.findViewById(R.id.iv);
        }
    }
}
